﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;



namespace SMSService
{
    public class SMManager
    {

        public SMManager()
        {
          
        }

        /// <summary>
        /// 初始化接口函数
        /// </summary>
        /// <returns></returns>
        private bool Message_Startup()
        {
            string dataBaseServer =System.Configuration.ConfigurationManager.AppSettings["dataBaseServer"];
            string dataBaseUserName = System.Configuration.ConfigurationManager.AppSettings["dataBaseUserName"];
            string dataBaseUserPwd = System.Configuration.ConfigurationManager.AppSettings["dataBaseUserPwd"];
            int ret = SMEntry.SP_Startup(dataBaseServer, dataBaseUserName, dataBaseUserPwd);
            
            //初始化成功
            return ret==0; 
            
        }

        /// <summary>
        /// 释放资源函数
        /// </summary>
        private void Message_Cleanup()
        {
            SMEntry.SP_Cleanup();
        }

        /// <summary>
        /// API调用登录函数
        /// </summary>
        private bool Message_Login()
        {
            string messageLoginUserName = System.Configuration.ConfigurationManager.AppSettings["messageLoginUserName"];
            string messageLoginUserPwd = System.Configuration.ConfigurationManager.AppSettings["messageLoginUserPwd"];
            int ret = SMEntry.SP_Login(messageLoginUserName, messageLoginUserPwd);

            return ret == 0;
            
        }

        /// <summary>
        /// 登出函数
        /// </summary>       
        private void Message_Logout()
        {
            SMEntry.SP_Logout();
        }

        public bool Message_Send(string destAddr, string content)
        {
            int iRet = SMEntry.SubmitShortMessage(DateTime.Now.ToString(), "1065750208520000", destAddr, content,
                        (uint)Encoding.Default.GetBytes(content).Length, 0, "MBJ0010500", "02", "10");
            return iRet == 0;
        }
    }
}